package com.cskaoyan.shiro;

import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
import org.springframework.stereotype.Component;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;

@Component
public class CustomWebSessionManager extends DefaultWebSessionManager {

    private static final String TOKEN = "X-CskaoyanMarket-Admin-Token";

    @Override
    protected Serializable getSessionId(ServletRequest servletRequest, ServletResponse response) {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        String sessionId = request.getHeader(TOKEN);
        if (sessionId != null && !"".equals(sessionId)) {
            return sessionId;
        }
        return super.getSessionId(request, response);
    }
}
